/**
 *
 */
package cn.dw.sg.aop;

import java.lang.annotation.Annotation;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author Administrator
 * @date 2018年6月13日 上午10:53:21
 * 
 */
//@Aspect
//@Component
public class LogAnnotationAdvice {
	
	@Pointcut("@annotation(cn.dw.sg.aop.LogAnnotation)")
	public void pintcut() {};
	
	
	
	@Before("pintcut()")
	public void doBefore(JoinPoint jointPoint) {
//		Class clazz = jointPoint.getTarget().getClass();
//		clazz.getMethods();
//		LogAnnotation anon = (LogAnnotation) clazz.getAnnotation(LogAnnotation.class);
//		System.out.println("&&&&&&&&&注解：" + anon.name());
		System.out.println("==========这里是前置方法doBefore-开始============");
		Object[] args = jointPoint.getArgs();
		System.out.println("#####3333args:"+ args.length);
		for(Object o : args) {
			System.out.println("参数:" + o);
		}
		System.out.println("==========这里是前置方法doBefore-结束============");
	}
	
	@After("pintcut()")
	public void doAfter() {
		System.out.println("==========这里是方法doAfter-============");
	}
	
	@AfterReturning("pintcut()")
	public void doReturning() {
		System.out.println("==========这里是方法doReturning-============");
	}
	
	@AfterThrowing("pintcut()")
	public void doThrowing() {
		System.out.println("==========这里是方法doThrowing-============");
	}
	
	@Around("pintcut()")
	public Object doArround(ProceedingJoinPoint pjp) throws Throwable {
		
		System.out.println("==========这里是方法doArround-============");
		
		 System.out.println("-----doAround().invoke-----");  
	        System.out.println(" 此处可以做类似于Before Advice的事情");  
	          
	        //调用核心逻辑  
	        Object retVal = pjp.proceed();  
	          
	        System.out.println(" 此处可以做类似于After Advice的事情");  
	        System.out.println("-----End of doAround()------");  
	        return retVal;  
	
	}
	
	

}
